local que_tiaolv = fk.CreateSkill {
    name = "que_tiaolv",
    anim_type = "offensive",
}

Fk:loadTranslationTable {
    ["que_tiaolv"] = "调律",
    [":que_tiaolv"] = "每轮开始时，你秘密观看并选择至多两名其他角色的各一张牌，若如此做，本轮结束时，若这些牌仍在其他角色的手牌中，持有这些牌的角色失去一点体力，" ..
        "然后你获得这些牌，若均已被消耗，你摸一张牌并执行一个额外的出牌阶段。",
}

que_tiaolv:addEffect(fk.RoundStart, {
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(que_tiaolv.name) and table.find(player.room.alive_players, function(p)
            return p:getHandcardNum() > 0
        end)
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player, { skill_name = que_tiaolv.name, prompt = "调律：是否选择至多两名角色的各一张牌并执行效果？" })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room:getOtherPlayers(player, false), function(p)
            return not p:isKongcheng() and p ~= player
        end)
        local tos = room:askToChoosePlayers(player, {
            targets = targets,
            min_num = 1,
            max_num = 2,
            prompt = "调律：请选择至多两名其他角色",
            skill_name = que_tiaolv.name,
            cancelable = false,
            no_indicate = true,
        })
        for _, id in ipairs(tos) do --观看并选择这么写
            local card = room:askToChooseCard(player,
                {
                    target = id,
                    flag = { card_data = { { id.general, id:getCardIds("h") } } },
                    skill_name = que_tiaolv.name
                })
            room:setCardMark(Fk:getCardById(card), "que_tiaolv", 1)
        end
    end,
})

que_tiaolv:addEffect(fk.RoundEnd, {
    can_trigger = function(self, event, target, player, data)
        local cards = {}
        for _, c in ipairs(player.room:getOtherPlayers(player)) do
            for _, card in ipairs(c:getCardIds("h")) do
                if Fk:getCardById(card):getMark("que_tiaolv") > 0 then
                    table.insertIfNeed(cards, card)
                end
            end
        end
        return player:hasSkill(que_tiaolv.name) and (#cards > 0 or #cards == 0)
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cards = {}
        for _, c in ipairs(room:getOtherPlayers(player)) do
            for _, card in ipairs(c:getCardIds("h")) do
                if Fk:getCardById(card):getMark("que_tiaolv") > 0 then
                    table.insertIfNeed(cards, card)
                    room:loseHp(c, 1, que_tiaolv.name)
                end
            end
        end
        if #cards > 0 then
            room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, que_tiaolv.name, nil, false, player)
        else
            player:drawCards(1, que_tiaolv.name)
            player:gainAnExtraPhase(Player.Play)
        end
    end,
})
return que_tiaolv
